<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/pub/includ.jsp"%>
<%
	String roleId = request.getParameter("roleId");
	String codeId = request.getParameter("codeId");
%>
<html>
	<head>
		<script type="text/javascript">
		
			$(function(){
				//加载两个要使用json分页的组件
		        loadGird("frm", 1);
			})
				
			//对第一个frm的回调函数, 方法的命名规则为callback_+表单id	
			var callback_frm = function(rows, frm) {
		       $.each(rows, function(i, n){
		    	   var row = $("#"+frm+" .template").clone().removeClass("template");
		           row.find(".klId").attr("value",n.id);
		       	   row.find(".klName").text(n.name);
		           row.find(".klEmail").text(n.email);
		           row.find(".klDesc").text(n.userid);
		           
		           row.attr("id","ready"+i);//改变绑定好数据的行的id
		           row.attr("class","tr_nbw");
		           row.appendTo("#"+frm+" .grid");//添加到模板的容器中
		       });   
			}
			
			var delUsersforRole = function(){
				var options = {
				type: 'POST',
				async: false,
				dataType: 'content-type',
				success: function(msg) {
					alert("删除成功！");
					document.location.reload();
				}
				}
				if(confirm('您确认要删除吗？')){
					//提交form
					document.getElementById("frm").action="<%=path %>/sys/role/delusers";
					$('#frm').ajaxSubmit(options);
				}
			}
			
			var  addUsersForRole = function(){
				selUser("{oId:\'users\',oName:\'usernames\',width:\'500\',height:\'300\',retfunc:\'saveRolesUser\'}",window);
			}
			var saveRolesUser=function(){
				var options = {
					type: 'POST',
					async: false,
					dataType: 'content-type',
					success: function(msg) {
						alert("添加成功！");
						window.location.reload();
					}
				}
				if(document.getElementById("users").value!=""){
					document.getElementById("frm").action="<%=path %>/sys/role/addusers";
					$('#frm').ajaxSubmit(options);
					document.getElementById("frm").action="<%=path %>/sys/role/showusers";
				}
			}
			function goback(){
				window.location = "<%=path%>/sys/role/get/roleList?codeId=<%=codeId %>";
			}
		</script>
	</head>
<body>
	<form name="frm" method="post" style="margin: 0" action="<%=path%>/sys/role/showusers" id="frm">
		<input type="hidden" name="roleId" value="<%=roleId %>"/>
		<input type="hidden" name="users" id="users" >
		<input type="hidden" name="usernames" id="usernames" >
		<table><tr><td height="2px"></td></tr></table>
		&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="#" onclick="addUsersForRole()" >添加用户</a>&nbsp;|&nbsp;
			<a href="#" onclick="delUsersforRole()" >移除用户</a>&nbsp;|&nbsp;
			<a href="#" onclick="goback()" >返回</a>
		<center>
		<table><tr><td height="2px"></td></tr></table>
		<table border="0" cellspacing="1" cellpadding="0" class="table_nbw  niceTable grid">
			<thead class="th_nbw">
				<tr >
					<td width="40px">
						<input type="checkbox" class="allCheck" />
					</td>
					<td>
						姓名
					</td>
					<td>
						email
					</td>
					<td>
						描 述
					</td>
				</tr>
			</thead>
			<tbody>
				<tr class="template klId">
					<td width="40px" class="idCheck">
						<input type="checkbox" name="chk" class="klId" />
					</td>
					<td class="klName niceTable-left"></td>
					<td class="klEmail niceTable-left"></td>
					<td class="klDesc niceTable-left"></td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<td align="right" colspan="10" >
						<img class="loading"
							src="<%=imgPath %>/large-loading.gif" width="20px"
							class="hidden" />
						<span class="pagediv"></span>
					</td>
				</tr>
			</tfoot>
		</table>
		</center>
	</form>

</body>
</html>